package com.btkjgc.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by _ESE on 2015/2/11.
 */
public class DateUtils
{
	public static java.util.Date getCurrentFormatDate()
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strDate = sdf.format(new java.util.Date());
		try
		{
			java.util.Date date = sdf.parse(strDate);
			return date;
		}
		catch (ParseException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	public static java.util.Date getDateTimeFromString(String date)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try
		{
			return sdf.parse(date);
		}
		catch (ParseException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	public static String getOnlyStringDate()
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String strDate = sdf.format(new Date());

		return strDate;
	}

	public static String getOnlyStringDateWeekAgo()
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date currentDate = new Date();
		long weekAgo = (currentDate.getTime() / 1000) - 60 * 60 * 24 * 7;
		currentDate.setTime(weekAgo * 1000);

		return sdf.format(currentDate);
	}

	public static String getDBFomatDate(String date)
	{
		String[] tempDate = date.split("/");
		date = tempDate[2] + "-" + tempDate[0] + "-" + tempDate[1];
		return date;
	}
}
